Programming with MicroPython: Embedded Programming with Microcontrollers and Python by Nicholas H. Tollervey

Programming with MicroPython: Embedded Programming with Microcontrollers and Python by Nicholas H. Tollervey

Author:Nicholas H. Tollervey [Tollervey, Nicholas H.]
Language: eng
Format: epub, pdf
Publisher: O'Reilly Media
Published: 2017-09-25T05:00:00+00:00


from microbit import * while True: if accelerometer.was_gesture('shake'): display.show(Image.ANGRY) elif accelerometer.was_gesture('face up'): display.show(Image.ASLEEP) elif accelerometer.was_gesture('up'): display.show(Image.HAPPY) sleep(100)

If the device is shaken, it displays an angry face; if it is flat but face up, it appears asleep; and if it is held upright, it’s happy to see you. The micro:bit can recognise the following list of gestures: up, down, left, right, face up, face down, freefall, 3g, 6g, 8g, and shake.

The micro:bit is the only device with an onboard magnetometer. It’s not very accurate and requires calibration before use. Calibration is achieved via the compass.calibrate method, which causes the device to wait until you’ve drawn a blocky circle on the display by rotating the device to move a pixel around the screen. Once calibrated, the micro:bit is able to report a heading with 0 as “north” (or some other strong magnetic field). Here’s how to turn the device into a compass that displays where the micro:bit thinks north is:



Download



Copyright Disclaimer:
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.